package com.jeeboot.modules.job.service.impl;

import com.jeeboot.modules.job.dao.ScheduleJobLogDao;
import com.jeeboot.modules.job.entity.ScheduleJobLogEntity;
import com.jeeboot.modules.job.service.ScheduleJobLogService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.Optional;

@Service("scheduleJobLogService")
public class ScheduleJobLogServiceImpl implements ScheduleJobLogService {
    @Autowired
    private ScheduleJobLogDao scheduleJobLogDao;

    @Override
    public Optional<ScheduleJobLogEntity> queryObject(Long jobId) {
        return scheduleJobLogDao.findById(jobId);
    }

    @Override
    public Page<ScheduleJobLogEntity> queryList(Map<String, Object> map, Pageable pageable) {

        if (map.containsKey("jobId") && StringUtils.isNotBlank(map.get("jobId").toString())) {
            return scheduleJobLogDao.findAllById(Long.parseLong(map.get("jobId").toString()),pageable);
        } else {
            return scheduleJobLogDao.findAll(pageable);
        }
    }

    @Override
    public Long queryTotal() {
        return scheduleJobLogDao.count();
    }

    @Override
    public void save(ScheduleJobLogEntity log) {
        scheduleJobLogDao.save(log);
    }

}
